package com.xyhuo.leetcode.january;

import com.xyhuo.leetcode.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * 二叉树的中序遍历
 * https://leetcode.cn/problems/binary-tree-inorder-traversal/
 *
 * @time 2024/1/4
 */
public class InorderTraversal {

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        search(root, ans);
        return ans;
    }

    private void search(TreeNode root, List<Integer> list) {
        if (root == null) {
            return;
        }
        search(root.left, list);
        list.add(root.val);
        search(root.right, list);
    }
}
